class Sprite extends Node {
    _texture = null;

    set texture(texture) {
        this._texture = texture;
        if (!this.shader)
            this.shader = createTextureShader(texture);
    }

    get texture() {
        return this._texture;
    }
    constructor(path) {
        super();
        Loader.load(path, (texture) => {
            this.texture = texture;
            this.width = texture.width;
            this.height = texture.height;
        });
    }
}

var Shaders = {};
Shaders.textures = {};
var createTextureShader = function (texture) {
    if (!Shaders.textures[texture.src]) {
        let shader = new Shader();
        shader.setValue("size", {
            type: ShaderValueType.Vec2,
            value: [canvas.width, canvas.height]
        });
        shader.setValue('texture', {
            type: ShaderValueType.Texture,
            index: 0,
            value: texture
        });
        shader.setAttributes([
            ["posuv", 4, gl.FLOAT]
        ]);
        Shaders.textures[texture.src] = shader;
    }
    return Shaders.textures[texture.src];
};